<template>
  <div class="register">
    <div class="content">
      <h1 class="reg">注 册</h1>
      <div class="content-form">
        <!-- form相关内容 -->
        <van-form @submit="onSubmit">
          <!-- v-model名字根据接口给的决定 -->
          <van-field
            v-model="phone"
            name="phone"
            label="手机号"
            placeholder="手机号"
            :rules="[{ validator, message: '请填写手机号' }]"
          />
          <van-field
            v-model="sms"
            center
            clearable
            label="短信验证码"
            placeholder="请输入短信验证码"
          >
            <template #button>
              <van-button size="small" type="info">发送验证码</van-button>
            </template>
          </van-field>
          <van-field
            v-model="password"
            type="password"
            name="password"
            label="密码"
            placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]"
          />
          <van-field
            v-model="password1"
            type="password"
            name="password1"
            label="确认密码"
            placeholder="确认密码"
            :rules="[{ required: true, message: '请填写确认密码' }]"
          />
          <div style="margin: 16px">
            <van-button
              round
              block
              type="info"
              native-type="submit"
              @click="$router.push('/personal')"
              >提交</van-button
            >
          </div>
        </van-form>
        <van-button round block type="info" @click="$router.push('/')"
          >去登录</van-button
        >
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Register",

  data() {
    return {
      phone: "",
      sms: "",
      password: "",
      password1: "",
    };
  },

  mounted() {},

  methods: {
    validator(val) {
      console.log(val);
      return /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1589]))\d{8}$/.test(
        val
      );
    },
    onSubmit(a) {
      console.log(a);
    },
  },
};
</script>
<style lang="scss" scoped>
.register {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  .content {
    .reg {
      font-size: 30px;
      font-weight: bold;
      margin-bottom: 20px;
      letter-spacing: 10px;
      margin-left: 10px;
    }
  }
}
</style>